`
https://leetcode.cn/problems/check-if-a-string-contains-all-binary-codes-of-size-k/
`

/**
 * @param {string} s
 * @param {number} k
 * @return {boolean}
 */
var hasAllCodes = function (s, k) {
  const n = s.length

  // 数字是否出现过
  const seen = new Array(2 ** k).fill(false)
  // 当前已经出现的数字个数
  let cur = 0
  let left = 0, right = 0

  while (right < n) {
    right++

    if (right - left >= k) {
      const target = parseInt(s.substring(left, right), 2)
      if (!seen[target]) {
        seen[target] = true
        cur++
      }
      // 如果已经出现了所有数字，返回 true
      if (cur === seen.length) return true

      left++
    }
  }

  return false
};